<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>缺件信息查询报表</title>
  <style>
    .el-dialog__title {
      color: #1E9FFF;
      font-weight: bold;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'缺件信息查询报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'">
        <el-form-item prop='mfgordername' label="订单号:">
          <el-autocomplete v-model.trim="queryInfo.mfgordername" placeholder="请输入订单号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchMfgorderAsync" :value-key="'mfgordername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>
        <el-form-item prop='engineno' label="发动机号:">
          <el-autocomplete v-model.trim="queryInfo.engineno" placeholder="请输入发动机号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchEngineNoAsync" :value-key="'engineno'" :debounce="500">
          </el-autocomplete>
        </el-form-item>
        <el-form-item prop='containerno' label="任务单号:">
          <el-autocomplete v-model.trim="queryInfo.containerno" placeholder="请输入任务单号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchContainerNoAsync" :value-key="'containerno'" :debounce="500">
          </el-autocomplete>
        </el-form-item>
        <el-form-item prop='partname' label="部件号:">
          <el-autocomplete v-model.trim="queryInfo.partname" placeholder="请输入部件号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="操作" width="140">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-view" size="mini" @click="showDetail(scope.row)">
              查看缺件
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="订单号" prop="mfgordername"></el-table-column>
        <el-table-column label="发动机号" prop="attributevalue"></el-table-column>
        <el-table-column label="任务单号" prop="containerno"></el-table-column>
        <el-table-column label="阶段名称" prop="workflowstepname"></el-table-column>
        <el-table-column label="部件号" prop="productname"></el-table-column>
        <el-table-column label="部件名称" prop="description"></el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[13,50,100]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>

      <el-dialog :center="true" :title="detail.title" :width="'95%'" :top="'10px'"
        :visible.sync="detail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="detail.dataList" stripe border>
          <el-table-column type="index" width="40"></el-table-column>
          <el-table-column label="件号" prop="productname"></el-table-column>
          <el-table-column label="名称" prop="description"></el-table-column>
          <el-table-column label="需求数量" prop="requestqty"></el-table-column>
          <el-table-column label="发料数量" prop="issueqty"></el-table-column>
          <el-table-column label="缺件数量" prop="lackqty"></el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination @current-change="handleDetailCurrentChange" :current-page="detail.queryInfo.currentPage"
          :page-sizes="[12]" :page-size="detail.queryInfo.pageSize" layout="prev,pager,next,jumper,sizes,total"
          :total="detail.total">
        </el-pagination>
      </el-dialog>
    </div>
  </div>

  <script type="module">
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: {
          factoryid: '',
          mfgordername: '',
          engineno: '',
          containerno: '',
          partname: '',
          currentPage: 1,//当前页
          pageSize: 13//每页显示条数
        },
        dataList: [],
        detail: {
          dialogVisiable: false,
          queryInfo: {
            engineno: '',
            containerno: '',
            mfgordername: '',
            currentPage: 1,//当前页
            pageSize: 12//每页显示条数
          },
          dataList: [],
          total: 0,
          title: ''
        }
      },
      methods: {
        async searchCommonAsync(config) {
          if (config.value && config.value.length >= 6) {
            const { data: { data, meta, total } } = await axios.post(`../handler/report/CommonActionHandle.ashx?action=${config.actionName}`, {
              type: config.actionName,
              [config.name]: config.value
            })
            if (meta.status === 500) {
              return this.$message.error(meta.msg);
            }
            const result = data.filter(item => item.rownum < 100);
            config.callback(result);
          }
        },
        searchMfgorderAsync(value, callback) {
          const config = { actionName: 'getMfgordernameAsync', name: 'mfgordername', value, callback };
          this.searchCommonAsync(config);
        },
        searchEngineNoAsync(value, callback) {
          const config = { actionName: 'getEngineNoAsync', name: 'engineno', value, callback };
          this.searchCommonAsync(config);
        },
        searchContainerNoAsync(value, callback) {
          const config = { actionName: 'getContainerNoAsync', name: 'containerno', value, callback };
          this.searchCommonAsync(config);
        },
        async searchProductAsync(value, callback) {
          const config = { actionName: 'getProductnameAsync', name: 'productname', value, callback };
          this.searchCommonAsync(config);
        },
        //查询数据
        async getData(currentpage) {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true
              this.loadingText = '数据加载中...'
              const { data: { data, meta, total } } = await axios.post('../handler/report/ZSIssueMissingPartsReport.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) {
                return this.$message.error(meta.msg);
              }
              this.dataList = data;
              this.total = total;
            }
          })
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        },
        // 批次明细 当前页 变更
        handleDetailCurrentChange(newPage) {
          this.detailQueryInfo.currentPage = newPage;
          this.getDetail();
        },
        showDetail(row) {
          this.detail.queryInfo.currentPage = 1;
          this.detail.title = `发动机:${row.attributevalue} 部件号:${row.productname} 缺件明细`;
          this.detail.dialogVisiable = true;
          this.detail.queryInfo.engineno = row.attributevalue;
          this.detail.queryInfo.mfgordername = row.mfgordername;
          this.detail.queryInfo.containerno = row.containerno;
          this.getDetail();
        },
        async getDetail() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/report/ZSIssueMissingPartsReport.ashx?action=getDetail', {
            type: 'getDetail',
            ...this.queryInfo,
            ...this.detail.queryInfo
          })

          this.loading = false;
          if (meta.status === 500) {
            return this.$message.error(meta.msg);
          }
          this.detail.dataList = data;
          this.detail.total = total;
        },
        handleDetailCurrentChange(newPage) {
          this.detail.queryInfo.currentPage = newPage;
          this.getDetail();
        },
      },
      watch: {
        queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true }
      }
    })
  </script>
</body>

</html>